<template>
  <a-modal
    :title="$t('详情')"
    :width="width"
    :visible="visible"
    @cancel="handleCancel"
    class="customHeight customHeightChild modal_title"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel">{{ $t('取消') }}</a-button>
    </template>
    <div>
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('券信息')">
                <a-input v-model="queryParam.couponInfo" :placeholder="$t('券号/名称')" />
              </a-form-item>
            </a-col>
            <a-col :xl="5" :lg="6" :md="7" :sm="24">
              <a-form-item :label="$t('状态')">
                <a-select v-model="queryParam.state" :placeholder="$t('请选择')">
                  <a-select-option v-for="(item, index) in stateList" :key="index" :value="item.value">
                    {{ item.title }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input v-model="queryParam.memberInfo" :placeholder="$t('手机号/卡号/姓名')" />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">{{ $t('查询') }}</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{
                  $t('重置')
                }}</a-button>
                <a-button
                type="primary"
                icon="download" :loading="exloading"
                style="margin-left: 8px"
                @click="handleExportXls($t('发券详情'))"
                >{{$t('导出')}}</a-button
              >
              </span>
            </a-col>
          </a-row>
          <a-row :gutter="24">
            <a-col :xl="11" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('发放时间')">
                <a-date-picker
                  :placeholder="$t('请选择开始时间')"
                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  class="query-group-cust"
                  v-model="queryParam.createTime_begin"
                  style="min-width: calc(50% - 10px)"
                ></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker
                  :placeholder="$t('请选择结束时间')"
                  :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  class="query-group-cust"
                  v-model="queryParam.createTime_end"
                  style="min-width: calc(50% - 10px)"
                ></a-date-picker>
              </a-form-item>
            </a-col>
            <a-col :xl="11" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('核销时间')">
                <a-date-picker
                  :placeholder="$t('请选择开始时间')"
                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  class="query-group-cust"
                  v-model="queryParam.updateTime_begin"
                  style="min-width: calc(50% - 10px)"
                ></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                  :placeholder="$t('请选择结束时间')"
                  class="query-group-cust"
                  v-model="queryParam.updateTime_end"
                  style="min-width: calc(50% - 10px)"
                ></a-date-picker>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <div>
        <a-table
          ref="table"
          size="middle"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="false"
          :loading="loading"
          class="j-table-force-nowrap"
        >
        </a-table>
      </div>
    </div>
  </a-modal>
</template>
<script>
import '@/assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import moment from 'moment'
export default {
  name: 'SendCouponDetailsModal',
  mixins: [JeecgListMixin],
  data() {
    return {
      moment,
      width: 1200,
      visible: false,
      columns: [
        {
          title: this.$t('券号'),
          align: 'center',
          dataIndex: 'id',
          width: '160px',
        },
        {
          title: this.$t('券名称'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('有效期'),
          align: 'center',
          dataIndex: 'validityEnd',
          customRender: (t, r) => {
            if (t) {
              return r.validityStart + '~' + r.validityEnd
            }
            return this.$t('不限期')
          },
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'memberPhone',
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'memberName',
        },
        {
          title: this.$t('发放时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('核销时间'),
          align: 'center',
          dataIndex: 'updateTime',
          customRender: (t, r) => {
            if (r.state=='3') {
              return t
            }
            return ''
          },
        },
      ],
      url: {
        list: '/member/bisMemberCoupon/list',
        exportXlsUrl: '/member/bisMemberCoupon/exportXls',
      },
      isCustom: true,
      model: {},
      stateList:[]
    }
  },
  created() {
    initDictOptions('bis_member_coupon.state').then((res) => {
      if (res.success) {
        this.stateList = res.result
      }
    })
  },
  methods: {
    show(record) {
      this.visible = true
      this.model = Object.assign({}, record)
      this.queryParam = { orderId: this.model.id, column: 'createTime', order: 'desc' }
      this.searchQuery()
    },
    searchReset() {
      this.queryParam = { orderId: this.model.id, column: 'createTime', order: 'desc' }
      this.searchQuery()
    },
    searchQuery() {
      if (this.queryParam.updateTime_begin) {
        this.queryParam.state = '3'
      }
      this.loadData(1)
    },
    handleCancel() {
      this.visible = false
    },
  },
}
</script>